const prompts = require("prompts");
const { commonPrompt } = require("./config/prompts.js");

// 询问用户选择
async function init() {
  const res = [];
  for (const promptFn of commonPrompt) {
    const params = promptFn(res);
    const response = await prompts(params);
    res.push(response);
  }
  const componenet = res[1].value;
  const componentName = res[2].value;
  const targetFilePath = res[3].value;
  if (targetFilePath) {
    generateCode(componenet, targetFilePath, componentName);
    console.log("代码生成成功！");
  } else {
    console.log("未输入目标文件路径，请重新输入！");
  }
  // 再次询问
  init();
}

// 执行代码生成
function generateCode(componenet, targetFilePath, componentName) {
  const ins = new componenet({ targetFilePath, componentName });
  ins.task();
}

init();
